package com.cskaoyan.wordmemorize.common.upload;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "ali.oss")
@ConditionalOnProperty(prefix = "ali.oss", name = "enable", havingValue = "true")
@Data
public class AliOssProperties {

    private String endpoint;
    private String accessKeyId;
    private String accessKeySecret;
    private String bucketName;


    @Bean(destroyMethod = "shutdown")
    public OSS aliOssUtil() {
        return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    }
}
